const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()-1

  return `${[year, month, day].map(formatNumber).join('/')}`
}


const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : `0${n}`
}

const time = () => {
  let myDate = new Date()
  let hour = myDate.getHours()
  let minute = myDate.getMinutes()
  let second = myDate.getSeconds()
  if(hour=="20") {
    console.log('时间到了')
    wx.cloud.callFunction({
      name: 'lu',
      data: {
        action: 'ordertime',
      },
      success(res) {
        console.log("云函数修改数据成功",res)
      },
      fail(res) {
        console.log("函数修改数据失败",res)
      }
    })
  }
}

module.exports = {
  formatTime,
  time
}
